angular.module('${menuCode}')
.filter('to_trusted', ['$sce', function ($sce) {
	return function (text) {
	    return $sce.trustAsHtml(text);
	};
}])
.controller("${widgetCode}Ctrl",function($scope,AppKit,$ionicActionSheet,$timeout,$state,$filter){
	$scope.loadProjListData = function() {
		$scope.paramter=$scope.searchWord;
		var url='/aeaipm/services/ProjInfo/rest/find-project-infos/';
		var promise = AppKit.getJsonApi(url); 
		console.log(url);
		promise.success(function(rspJson){
			$scope.projectInfos=rspJson.projectInfos
			$scope.projectInfos=$filter('orderBy')($scope.projectInfos,'piCreateTime');
		});  
	}
	$scope.loadProjListData();
	
	$scope.FirstMenu = function(ptId){
	      var hideSheet = $ionicActionSheet.show({
	          buttons: [
	            { text: '<b>计划管理</b> ' },
	            { text: '<b>项目周报</b> ' },
	            { text: '<b>项目追踪</b> ' },
	            { text: '<b>缺陷统计</b> ' }
	          ],
	          titleText: '请选择功能',
	          cancelText: '取消',
	          cancel: function() {
	               // add cancel code..
	          },
	          buttonClicked: function(index) {
	        	  switch(index){
		        	  case 0:
		        		  $state.go("tab.project-plan",{"piId": $scope.piId,"piName":$scope.piName}); 
		        		  break;
		        	  case 1:
		        		  $state.go("tab.project-weekly",{"piId": $scope.piId,"piName":$scope.piName}); 
		        		  break;
		        	  case 2:
		        		  $state.go("tab.project-track",{"piId": $scope.piId,"piName":$scope.piName});
		        		  break;
		        	  case 3:
		        		  $state.go("tab.project-statistics",{"piId": $scope.piId,"ptId":ptId,"piName":$scope.piName});
		        		  break;
	        	  }
	        	  return true; 
	          }
	      });
	/*
	      $timeout(function() {
	          hideSheet();
	      }, 5000); */
    }

	$scope.SecondMenu = function(ptId){
	    var hideSheet = $ionicActionSheet.show({
	        buttons: [
	          { text: '<b>项目计划</b> ' },
	          { text: '<b>项目周报</b> ' },
	          { text: '<b>项目追踪</b> ' }
	        ],
	        titleText: '请选择您的操作',
	        cancelText: '取消',
	        cancel: function() {
	             // add cancel code..
	        },
	        buttonClicked: function(index) {
	        	switch(index){
	        	  case 0:
	        		  $state.go("tab.project-plan",{"piId": $scope.piId,"piName":$scope.piName});  
	        		  break;
	        	  case 1:
	        		  $state.go("tab.project-weekly",{"piId": $scope.piId,"piName":$scope.piName}); 
	        		  break;
	        	  case 2:
	        		  $state.go("tab.project-track",{"piId": $scope.piId,"piName":$scope.piName});
	        		  break;
	        	  }
	        	  return true; 
	        }
	    });
	
	    $timeout(function() {
	        hideSheet();
	    }, 5000); 
	}
	
	$scope.popMenu=function(isActiveTest,ptId,piId,piName){
		$scope.piId=piId;
		$scope.piName=piName;
		if(isActiveTest){
			$scope.FirstMenu(ptId);
		}else{
			$scope.SecondMenu(ptId);
		}
	}
});